/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CompetenceEditorView.java
 *
 * Created on Jul 27, 2010, 3:37:36 PM
 */

package at.tugraz.kmi.css.cbkst2.prereq.structurevis;

import java.util.ServiceLoader;

import javax.swing.JFrame;
import javax.swing.WindowConstants;

import at.tugraz.kmi.css.cbkst2.CbKSTVertex;

import com.google.inject.Guice;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.jgoodies.binding.adapter.BasicComponentFactory;

/**
 * The Editor View for a competence.
 * 
 * @author Georg Öttl
 */
public final class CompetenceEditorView extends javax.swing.JPanel {

	/**
	 * 
	 */
	private static final long	serialVersionUID	= 1L;
	private CompetenceModel		model;

	public static void main(String[] args) {
		Provider<CompetenceEditorView> provider = Guice.createInjector(
				ServiceLoader.load(com.google.inject.Module.class))
				.getProvider(CompetenceEditorView.class);
		CompetenceEditorView viewer = provider.get();
		viewer.model.getBean().setName("test");
		JFrame frame = new JFrame();
		frame.getContentPane().add(viewer);
		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		frame.pack();
		frame.setVisible(true);
	}

	/** Creates new form CompetenceEditorView */
	public CompetenceEditorView() {
		initComponents();
	}

	/** Creates new form CompetenceEditorView */
	@Inject
	CompetenceEditorView(CompetenceModel model) {
		this.model = model;
		initComponents();
		initActions();
	}

	private void initActions() {
		jButtonApply.setAction(model.getApplyAction());
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed"
	// <editor-fold defaultstate="collapsed"
	// <editor-fold defaultstate="collapsed"
	// <editor-fold defaultstate="collapsed"
	// desc="Generated Code">//GEN-BEGIN:initComponents
	private void initComponents() {

		jTextFieldName = BasicComponentFactory.createTextField(
				model.getModel(CbKSTVertex.PROPERTY_NAME), true);
		jScrollPane1 = new javax.swing.JScrollPane();
		jTextAreaDescription = BasicComponentFactory.createTextArea(
				model.getModel(CbKSTVertex.PROPERTY_DESCRIPTION), true);
		jLabel1 = new javax.swing.JLabel();
		jLabel2 = new javax.swing.JLabel();
		jButtonApply = new javax.swing.JButton();

		setMaximumSize(new java.awt.Dimension(270, 260));
		setMinimumSize(new java.awt.Dimension(270, 240));
		setPreferredSize(new java.awt.Dimension(270, 250));

		jTextFieldName.setMaximumSize(new java.awt.Dimension(162, 2147483647));
		jTextFieldName.setMinimumSize(new java.awt.Dimension(162, 27));
		jTextFieldName.addActionListener(new java.awt.event.ActionListener() {
			@Override
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jTextFieldNameActionPerformed(evt);
			}
		});

		jTextAreaDescription.setColumns(20);
		jTextAreaDescription.setLineWrap(true);
		jTextAreaDescription.setRows(5);
		jScrollPane1.setViewportView(jTextAreaDescription);

		jLabel1.setText("Name");

		jLabel2.setText("Description");

		jButtonApply.setText("Apply");

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
		setLayout(layout);
		layout.setHorizontalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addContainerGap()
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING)
												.addGroup(
														javax.swing.GroupLayout.Alignment.TRAILING,
														layout.createSequentialGroup()
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.LEADING)
																				.addComponent(
																						jLabel2)
																				.addComponent(
																						jLabel1))
																.addPreferredGap(
																		javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.TRAILING)
																				.addComponent(
																						jTextFieldName,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						162,
																						Short.MAX_VALUE)
																				.addComponent(
																						jScrollPane1,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						162,
																						Short.MAX_VALUE)))
												.addComponent(
														jButtonApply,
														javax.swing.GroupLayout.Alignment.TRAILING))
								.addContainerGap()));
		layout.setVerticalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addContainerGap()
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(jLabel1)
												.addComponent(
														jTextFieldName,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														27,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING)
												.addComponent(jLabel2)
												.addComponent(
														jScrollPane1,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														158, Short.MAX_VALUE))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addComponent(jButtonApply).addContainerGap()));
	}// </editor-fold>//GEN-END:initComponents

	private void jTextFieldNameActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jTextFieldNameActionPerformed
		// TODO add your handling code here:
	}// GEN-LAST:event_jTextFieldNameActionPerformed

	// Variables declaration - do not modify//GEN-BEGIN:variables
	private javax.swing.JButton		jButtonApply;
	private javax.swing.JLabel		jLabel1;
	private javax.swing.JLabel		jLabel2;
	private javax.swing.JScrollPane	jScrollPane1;
	private javax.swing.JTextArea	jTextAreaDescription;
	private javax.swing.JTextField	jTextFieldName;
	// End of variables declaration//GEN-END:variables

}
